//
//  JKTabBarController.swift
//  afanti
//
//  Created by albert on 16/4/15.
//  Copyright © 2016年 albert. All rights reserved.
//

import UIKit

class JKTabBarController: UITabBarController {
    
    override class func initialize(){
        
        //UITabBarItem
        let item = UITabBarItem.appearance()
        var attr: Dictionary<String,AnyObject> = [NSFontAttributeName : UIFont.systemFontOfSize(9)]
        attr[NSForegroundColorAttributeName] = UIColor.init(red: 115/255.0, green: 115/255.0, blue: 115/255.0, alpha: 1)
        item.setTitleTextAttributes(attr, forState: UIControlState.Normal)
        
        var selectedAttr: Dictionary<String,AnyObject> = [NSFontAttributeName : UIFont.systemFontOfSize(11)]
        selectedAttr[NSForegroundColorAttributeName] = UIColor.whiteColor()
        item.setTitleTextAttributes(selectedAttr, forState: UIControlState.Selected)
        
        //底部tabaBar
        let tabBar = UITabBar.appearance()
        tabBar.barTintColor = UIColor.init(red: 45/255.0, green: 45/255.0, blue: 45/255.0, alpha: 1)
    }
    
    override func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIStatusBarStyle.LightContent
    }

    override func viewDidLoad() {
        super.viewDidLoad()
        
        //创建子控制器
        setupChildViewController(JKHomeViewController(), title: "拍照提问", normalImage: "aft_camera", selectedImage: "aft_camera_selected")
        setupChildViewController(JKSquareTableViewController(), title: "答题广场", normalImage: "aft_square", selectedImage: "aft_square_selected")
        setupChildViewController(JKMessageViewController(), title: "消息", normalImage: "aft_message", selectedImage: "aft_message_selected")
        setupChildViewController(JKPersonalCenterViewController(), title: "个人中心", normalImage: "aft_person", selectedImage: "aft_person_selected")
    }
    
    //创建子控制器
    func setupChildViewController(viewController: UIViewController, title:String, normalImage: String, selectedImage: String){
        viewController.title = title
        viewController.tabBarItem.image = UIImage(named: normalImage)
        viewController.tabBarItem.selectedImage = UIImage(named: selectedImage)
        
        
        let nav = JKNavigationController(rootViewController: viewController)
        
        self.addChildViewController(nav)
    }

}
